<?
    /**
     * PrincipioLab
     *
     * @package    PrincipioLab
     */

    /**
     * PrincipioLab_Mapper
     *
     * @package    PrincipioLab
     */
    abstract class PrincipioLab_Mapper
    {
        /** @var null|Zend_Db_Table_Abstract */
        protected static $db_table = null;

        /** @var null|PrincipioLab_LinkedList */
        protected static $collection_full = null;

        /** @var null|PrincipioLab_LinkedList */
        protected static $collection_partial = null;


        /**
         * @return null|PrincipioLab_LinkedList
         */
        protected static function getCollectionFull()
        {
            return static::$collection_full;
        }


        /**
         * @param null|PrincipioLab_IComparator $icomparator
         *
         * @return PrincipioLab_LinkedList
         */
        protected static function getCollectionPartial(PrincipioLab_IComparator $icomparator = null)
        {
            if (is_null(static::$collection_partial))
                static::$collection_partial = new PrincipioLab_LinkedList($icomparator);

            return static::$collection_partial;
        }


        /**
         * @param $id mixed
         *
         * @return bool|PrincipioLab_IDAble
         */
        protected static function lookupCollectionPartial($id)
        {
            return self::getCollectionPartial()->getItem($id);
        }


        /**
         * @param $id mixed
         *
         * @return bool|PrincipioLab_IDAble
         */
        protected static function lookupCollectionFull($id)
        {
            $collection_full = self::getCollectionFull();

            return (is_null($collection_full) ? false : $collection_full->getItem($id));
        }


        /**
         * @param $id mixed
         *
         * @return bool|PrincipioLab_IDAble
         */
        protected static function lookupCollections($id)
        {
            if (($model = self::lookupCollectionPartial($id)) !== false)
                return $model;
            else
                return self::lookupCollectionFull($id);
        }


        /**
         * @throws RuntimeException
         */
        protected static function getPrefix()
        {
            throw new RuntimeException("Unimplemented");
        }


        /**
         * @throws RuntimeException
         */
        protected static function getDbTableName()
        {
            throw new RuntimeException("Unimplemented");
        }


        /**
         * @return null|Zend_Db_Table_Abstract
         */
        public static function getDBTable()
        {
            if (is_null(static::$db_table))
            {
                $t = static::getPrefix() . "_Model_DbTable_" . static::getDbTableName();
                static::$db_table = new $t;
            };

            return static::$db_table;
        }


        /**
         * @param string     $message
         * @param int        $priority
         * @param string     $prefixes
         * @param null|mixed $extras
         *
         * @return void
         */
        public static function log($message, $priority, $prefixes = "", $extras = null)
        {
            Zend_Registry::get('log')->log("[DATABASE]" . $prefixes . " " . $message, $priority, $extras);
        }


        /**
         * @param Exception $ex
         * @param string    $message
         * @param string    $prefixes
         *
         * @return bool
         */
        public static function dbException(Exception $ex, $message, $prefixes = "")
        {
            self::log($message, Zend_Log::EMERG, $prefixes, $ex);
            return false;
        }
    };
?>